package androidx.appcompat.widget;

import android.app.PendingIntent;
import android.app.SearchableInfo;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable.ConstantState;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.ClassLoaderCreator;
import android.os.Parcelable.Creator;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ImageSpan;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.KeyEvent.DispatcherState;
import android.view.LayoutInflater;
import android.view.TouchDelegate;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnKeyListener;
import android.view.ViewConfiguration;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AutoCompleteTextView;
import android.widget.ImageView;
import android.widget.TextView.OnEditorActionListener;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.core.view.ViewCompat;
import androidx.cursoradapter.widget.CursorAdapter;
import androidx.customview.view.AbsSavedState;
import com.huawei.hms.actions.SearchIntents;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.lang.reflect.Method;
import java.util.WeakHashMap;
import o.ah.g;
import o.ah.h;
import o.ah.i;
import o.ah.j;
import o.at;
import o.cw;
import o.cz;
import o.de;

public class SearchView extends LinearLayoutCompat implements at {
    static final d ʻ = new d();
    private Rect ʻॱ;
    OnKeyListener ʼ;
    private final int ʼॱ;
    CursorAdapter ʽ;
    private final Drawable ʽॱ;
    private final Intent ʾ;
    private final Intent ʿ;
    private final int ˈ;
    private OnClickListener ˉ;
    final SearchAutoComplete ˊ;
    private b ˊˊ;
    private e ˊˋ;
    private final View ˊॱ;
    private final CharSequence ˊᐝ;
    final ImageView ˋ;
    private c ˋˊ;
    private boolean ˋˋ;
    private final View ˋॱ;
    private boolean ˋᐝ;
    private CharSequence ˌ;
    private boolean ˍ;
    final ImageView ˎ;
    private boolean ˎˎ;
    private int ˎˏ;
    final ImageView ˏ;
    private CharSequence ˏˎ;
    private boolean ˏˏ;
    private final View ˏॱ;
    private CharSequence ˑ;
    private a ͺ;
    private boolean ͺॱ;
    private Bundle ـ;
    final ImageView ॱ;
    private Runnable ॱʻ;
    private final Runnable ॱʼ;
    private int ॱʽ;
    private final View ॱˊ;
    private Rect ॱˋ;
    private int[] ॱˎ;
    private boolean ॱͺ;
    SearchableInfo ॱॱ;
    private int[] ॱᐝ;
    OnFocusChangeListener ᐝ;
    private final OnEditorActionListener ᐝˊ;
    private final OnClickListener ᐝˋ;
    private final ImageView ᐝॱ;
    private final WeakHashMap<String, ConstantState> ᐝᐝ;
    private final OnItemClickListener ᐧ;
    private final OnItemSelectedListener ᐨ;
    private TextWatcher ꜟ;

    static class SavedState extends AbsSavedState {
        public static final Creator<SavedState> CREATOR = new ClassLoaderCreator<SavedState>() {
            public /* synthetic */ Object createFromParcel(Parcel parcel) {
                return ॱ(parcel);
            }

            public /* synthetic */ Object createFromParcel(Parcel parcel, ClassLoader classLoader) {
                return ˎ(parcel, classLoader);
            }

            public /* synthetic */ Object[] newArray(int i) {
                return ˊ(i);
            }

            public SavedState ˎ(Parcel parcel, ClassLoader classLoader) {
                return new SavedState(parcel, classLoader);
            }

            public SavedState ॱ(Parcel parcel) {
                return new SavedState(parcel, null);
            }

            public SavedState[] ˊ(int i) {
                return new SavedState[i];
            }
        };
        boolean ˎ;

        SavedState(Parcelable parcelable) {
            super(parcelable);
        }

        public SavedState(Parcel parcel, ClassLoader classLoader) {
            super(parcel, classLoader);
            this.ˎ = ((Boolean) parcel.readValue(null)).booleanValue();
        }

        public void writeToParcel(Parcel parcel, int i) {
            super.writeToParcel(parcel, i);
            parcel.writeValue(Boolean.valueOf(this.ˎ));
        }

        public String toString() {
            return "SearchView.SavedState{" + Integer.toHexString(System.identityHashCode(this)) + " isIconified=" + this.ˎ + "}";
        }
    }

    @RestrictTo({androidx.annotation.RestrictTo.d.ˊ})
    public static class SearchAutoComplete extends AppCompatAutoCompleteTextView {
        private boolean ˋ;
        private SearchView ˎ;
        final Runnable ˏ;
        private int ॱ;

        public SearchAutoComplete(Context context) {
            this(context, null);
        }

        public SearchAutoComplete(Context context, AttributeSet attributeSet) {
            this(context, attributeSet, o.ah.c.ॱᐝ);
        }

        public SearchAutoComplete(Context context, AttributeSet attributeSet, int i) {
            super(context, attributeSet, i);
            this.ˏ = new 1(this);
            this.ॱ = getThreshold();
        }

        protected void onFinishInflate() {
            super.onFinishInflate();
            setMinWidth((int) TypedValue.applyDimension(1, (float) ˎ(), getResources().getDisplayMetrics()));
        }

        void ˋ(SearchView searchView) {
            this.ˎ = searchView;
        }

        public void setThreshold(int i) {
            super.setThreshold(i);
            this.ॱ = i;
        }

        boolean ˋ() {
            return TextUtils.getTrimmedLength(getText()) == 0;
        }

        protected void replaceText(CharSequence charSequence) {
        }

        public void performCompletion() {
        }

        public void onWindowFocusChanged(boolean z) {
            super.onWindowFocusChanged(z);
            if (z && this.ˎ.hasFocus() && getVisibility() == 0) {
                this.ˋ = true;
                if (SearchView.ˎ(getContext())) {
                    SearchView.ʻ.ˊ(this, true);
                }
            }
        }

        protected void onFocusChanged(boolean z, int i, Rect rect) {
            super.onFocusChanged(z, i, rect);
            this.ˎ.ˋॱ();
        }

        public boolean enoughToFilter() {
            return this.ॱ <= 0 || super.enoughToFilter();
        }

        public boolean onKeyPreIme(int i, KeyEvent keyEvent) {
            if (i == 4) {
                DispatcherState keyDispatcherState;
                if (keyEvent.getAction() == 0 && keyEvent.getRepeatCount() == 0) {
                    keyDispatcherState = getKeyDispatcherState();
                    if (keyDispatcherState == null) {
                        return true;
                    }
                    keyDispatcherState.startTracking(keyEvent, this);
                    return true;
                } else if (keyEvent.getAction() == 1) {
                    keyDispatcherState = getKeyDispatcherState();
                    if (keyDispatcherState != null) {
                        keyDispatcherState.handleUpEvent(keyEvent);
                    }
                    if (keyEvent.isTracking() && !keyEvent.isCanceled()) {
                        this.ˎ.clearFocus();
                        ˏ(false);
                        return true;
                    }
                }
            }
            return super.onKeyPreIme(i, keyEvent);
        }

        private int ˎ() {
            Configuration configuration = getResources().getConfiguration();
            int i = configuration.screenWidthDp;
            int i2 = configuration.screenHeightDp;
            if (i >= 960 && i2 >= 720 && configuration.orientation == 2) {
                return 256;
            }
            if (i >= 600 || (i >= 640 && i2 >= 480)) {
                return 192;
            }
            return 160;
        }

        public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
            InputConnection onCreateInputConnection = super.onCreateInputConnection(editorInfo);
            if (this.ˋ) {
                removeCallbacks(this.ˏ);
                post(this.ˏ);
            }
            return onCreateInputConnection;
        }

        void ˏ() {
            if (this.ˋ) {
                ((InputMethodManager) getContext().getSystemService("input_method")).showSoftInput(this, 0);
                this.ˋ = false;
            }
        }

        void ˏ(boolean z) {
            InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService("input_method");
            if (!z) {
                this.ˋ = false;
                removeCallbacks(this.ˏ);
                inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
            } else if (inputMethodManager.isActive(this)) {
                this.ˋ = false;
                removeCallbacks(this.ˏ);
                inputMethodManager.showSoftInput(this, 0);
            } else {
                this.ˋ = true;
            }
        }
    }

    static class a extends TouchDelegate {
        private final View ˊ;
        private final Rect ˋ = new Rect();
        private final Rect ˎ = new Rect();
        private final Rect ˏ = new Rect();
        private final int ॱ;
        private boolean ॱॱ;

        public a(Rect rect, Rect rect2, View view) {
            super(rect, view);
            this.ॱ = ViewConfiguration.get(view.getContext()).getScaledTouchSlop();
            ॱ(rect, rect2);
            this.ˊ = view;
        }

        public void ॱ(Rect rect, Rect rect2) {
            this.ˋ.set(rect);
            this.ˎ.set(rect);
            this.ˎ.inset(-this.ॱ, -this.ॱ);
            this.ˏ.set(rect2);
        }

        /* JADX WARNING: inconsistent code. */
        /* Code decompiled incorrectly, please refer to instructions dump. */
        public boolean onTouchEvent(android.view.MotionEvent r7) {
            /*
            r6 = this;
            r1 = 1;
            r0 = 0;
            r2 = r7.getX();
            r3 = (int) r2;
            r2 = r7.getY();
            r4 = (int) r2;
            r2 = r7.getAction();
            switch(r2) {
                case 0: goto L_0x003c;
                case 1: goto L_0x0048;
                case 2: goto L_0x0048;
                case 3: goto L_0x0056;
                default: goto L_0x0013;
            };
        L_0x0013:
            r2 = r0;
        L_0x0014:
            if (r2 == 0) goto L_0x003b;
        L_0x0016:
            if (r1 == 0) goto L_0x005b;
        L_0x0018:
            r0 = r6.ˏ;
            r0 = r0.contains(r3, r4);
            if (r0 != 0) goto L_0x005b;
        L_0x0020:
            r0 = r6.ˊ;
            r0 = r0.getWidth();
            r0 = r0 / 2;
            r0 = (float) r0;
            r1 = r6.ˊ;
            r1 = r1.getHeight();
            r1 = r1 / 2;
            r1 = (float) r1;
            r7.setLocation(r0, r1);
        L_0x0035:
            r0 = r6.ˊ;
            r0 = r0.dispatchTouchEvent(r7);
        L_0x003b:
            return r0;
        L_0x003c:
            r2 = r6.ˋ;
            r2 = r2.contains(r3, r4);
            if (r2 == 0) goto L_0x0013;
        L_0x0044:
            r6.ॱॱ = r1;
            r2 = r1;
            goto L_0x0014;
        L_0x0048:
            r2 = r6.ॱॱ;
            if (r2 == 0) goto L_0x0014;
        L_0x004c:
            r5 = r6.ˎ;
            r5 = r5.contains(r3, r4);
            if (r5 != 0) goto L_0x0014;
        L_0x0054:
            r1 = r0;
            goto L_0x0014;
        L_0x0056:
            r2 = r6.ॱॱ;
            r6.ॱॱ = r0;
            goto L_0x0014;
        L_0x005b:
            r0 = r6.ˏ;
            r0 = r0.left;
            r0 = r3 - r0;
            r0 = (float) r0;
            r1 = r6.ˏ;
            r1 = r1.top;
            r1 = r4 - r1;
            r1 = (float) r1;
            r7.setLocation(r0, r1);
            goto L_0x0035;
            */
            throw new UnsupportedOperationException("Method not decompiled: androidx.appcompat.widget.SearchView.a.onTouchEvent(android.view.MotionEvent):boolean");
        }
    }

    public interface c {
        boolean ˋ();
    }

    static class d {
        private Method ˊ;
        private Method ˏ;
        private Method ॱ;

        d() {
            try {
                this.ˏ = AutoCompleteTextView.class.getDeclaredMethod("doBeforeTextChanged", new Class[0]);
                this.ˏ.setAccessible(true);
            } catch (NoSuchMethodException e) {
            }
            try {
                this.ॱ = AutoCompleteTextView.class.getDeclaredMethod("doAfterTextChanged", new Class[0]);
                this.ॱ.setAccessible(true);
            } catch (NoSuchMethodException e2) {
            }
            try {
                this.ˊ = AutoCompleteTextView.class.getMethod("ensureImeVisible", new Class[]{Boolean.TYPE});
                this.ˊ.setAccessible(true);
            } catch (NoSuchMethodException e3) {
            }
        }

        void ॱ(AutoCompleteTextView autoCompleteTextView) {
            if (this.ˏ != null) {
                try {
                    this.ˏ.invoke(autoCompleteTextView, new Object[0]);
                } catch (Exception e) {
                }
            }
        }

        void ˏ(AutoCompleteTextView autoCompleteTextView) {
            if (this.ॱ != null) {
                try {
                    this.ॱ.invoke(autoCompleteTextView, new Object[0]);
                } catch (Exception e) {
                }
            }
        }

        void ˊ(AutoCompleteTextView autoCompleteTextView, boolean z) {
            if (this.ˊ != null) {
                try {
                    this.ˊ.invoke(autoCompleteTextView, new Object[]{Boolean.valueOf(z)});
                } catch (Exception e) {
                }
            }
        }
    }

    public interface e {
        boolean ˋ(String str);

        boolean ॱ(String str);
    }

    public SearchView(Context context) {
        this(context, null);
    }

    public SearchView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, o.ah.c.ˑ);
    }

    public SearchView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ॱˋ = new Rect();
        this.ʻॱ = new Rect();
        this.ॱᐝ = new int[2];
        this.ॱˎ = new int[2];
        this.ॱʼ = new 2(this);
        this.ॱʻ = new 4(this);
        this.ᐝᐝ = new WeakHashMap();
        this.ᐝˋ = new 8(this);
        this.ʼ = new 6(this);
        this.ᐝˊ = new 7(this);
        this.ᐧ = new 9(this);
        this.ᐨ = new 10(this);
        this.ꜟ = new 5(this);
        cw ॱ = cw.ॱ(context, attributeSet, g.ˊꞌ, i, 0);
        LayoutInflater.from(context).inflate(ॱ.ॱॱ(g.ˋˑ, j.ॱˋ), this, true);
        this.ˊ = (SearchAutoComplete) findViewById(i.ͺॱ);
        this.ˊ.ˋ(this);
        this.ˏॱ = findViewById(i.ˌ);
        this.ˋॱ = findViewById(i.ˎˎ);
        this.ˊॱ = findViewById(i.ॱʻ);
        this.ॱ = (ImageView) findViewById(i.ˉ);
        this.ˏ = (ImageView) findViewById(i.ˍ);
        this.ˋ = (ImageView) findViewById(i.ˋᐝ);
        this.ˎ = (ImageView) findViewById(i.ˎˏ);
        this.ᐝॱ = (ImageView) findViewById(i.ˋˋ);
        ViewCompat.ˏ(this.ˋॱ, ॱ.ˋ(g.ˌˎ));
        ViewCompat.ˏ(this.ˊॱ, ॱ.ˋ(g.ˍˏ));
        this.ॱ.setImageDrawable(ॱ.ˋ(g.ˋﾞ));
        this.ˏ.setImageDrawable(ॱ.ˋ(g.ˋᶥ));
        this.ˋ.setImageDrawable(ॱ.ˋ(g.ˋᐧ));
        this.ˎ.setImageDrawable(ॱ.ˋ(g.ˋꞌ));
        this.ᐝॱ.setImageDrawable(ॱ.ˋ(g.ˋﾞ));
        this.ʽॱ = ॱ.ˋ(g.ˋꜞ);
        cz.ˋ(this.ॱ, getResources().getString(h.ˋॱ));
        this.ˈ = ॱ.ॱॱ(g.ˍˎ, j.ॱᐝ);
        this.ʼॱ = ॱ.ॱॱ(g.ˌˏ, 0);
        this.ॱ.setOnClickListener(this.ᐝˋ);
        this.ˋ.setOnClickListener(this.ᐝˋ);
        this.ˏ.setOnClickListener(this.ᐝˋ);
        this.ˎ.setOnClickListener(this.ᐝˋ);
        this.ˊ.setOnClickListener(this.ᐝˋ);
        this.ˊ.addTextChangedListener(this.ꜟ);
        this.ˊ.setOnEditorActionListener(this.ᐝˊ);
        this.ˊ.setOnItemClickListener(this.ᐧ);
        this.ˊ.setOnItemSelectedListener(this.ᐨ);
        this.ˊ.setOnKeyListener(this.ʼ);
        this.ˊ.setOnFocusChangeListener(new 3(this));
        setIconifiedByDefault(ॱ.ˋ(g.ˋˈ, true));
        int ˎ = ॱ.ˎ(g.ˊﾞ, -1);
        if (ˎ != -1) {
            setMaxWidth(ˎ);
        }
        this.ˊᐝ = ॱ.ˊ(g.ˋﾟ);
        this.ˌ = ॱ.ˊ(g.ˋˉ);
        ˎ = ॱ.ॱ(g.ˋᐨ, -1);
        if (ˎ != -1) {
            setImeOptions(ˎ);
        }
        ˎ = ॱ.ॱ(g.ˋʿ, -1);
        if (ˎ != -1) {
            setInputType(ˎ);
        }
        setFocusable(ॱ.ˋ(g.ˋʾ, true));
        ॱ.ॱ();
        this.ʿ = new Intent("android.speech.action.WEB_SEARCH");
        this.ʿ.addFlags(268435456);
        this.ʿ.putExtra("android.speech.extra.LANGUAGE_MODEL", "web_search");
        this.ʾ = new Intent("android.speech.action.RECOGNIZE_SPEECH");
        this.ʾ.addFlags(268435456);
        this.ॱˊ = findViewById(this.ˊ.getDropDownAnchor());
        if (this.ॱˊ != null) {
            this.ॱˊ.addOnLayoutChangeListener(new 1(this));
        }
        ˎ(this.ˎˎ);
        ʿ();
    }

    int ˏ() {
        return this.ˈ;
    }

    int ॱ() {
        return this.ʼॱ;
    }

    public void setSearchableInfo(SearchableInfo searchableInfo) {
        this.ॱॱ = searchableInfo;
        if (this.ॱॱ != null) {
            ʽॱ();
            ʿ();
        }
        this.ͺॱ = ᐝॱ();
        if (this.ͺॱ) {
            this.ˊ.setPrivateImeOptions("nm");
        }
        ˎ(ʽ());
    }

    @RestrictTo({androidx.annotation.RestrictTo.d.ˊ})
    public void setAppSearchData(Bundle bundle) {
        this.ـ = bundle;
    }

    public void setImeOptions(int i) {
        this.ˊ.setImeOptions(i);
    }

    public void setInputType(int i) {
        this.ˊ.setInputType(i);
    }

    public boolean requestFocus(int i, Rect rect) {
        if (this.ˏˏ || !isFocusable()) {
            return false;
        }
        if (ʽ()) {
            return super.requestFocus(i, rect);
        }
        boolean requestFocus = this.ˊ.requestFocus(i, rect);
        if (requestFocus) {
            ˎ(false);
        }
        return requestFocus;
    }

    public void clearFocus() {
        this.ˏˏ = true;
        super.clearFocus();
        this.ˊ.clearFocus();
        this.ˊ.ˏ(false);
        this.ˏˏ = false;
    }

    public void setOnQueryTextListener(e eVar) {
        this.ˊˋ = eVar;
    }

    public void setOnCloseListener(c cVar) {
        this.ˋˊ = cVar;
    }

    public void setOnQueryTextFocusChangeListener(OnFocusChangeListener onFocusChangeListener) {
        this.ᐝ = onFocusChangeListener;
    }

    public void setOnSuggestionListener(b bVar) {
        this.ˊˊ = bVar;
    }

    public void setOnSearchClickListener(OnClickListener onClickListener) {
        this.ˉ = onClickListener;
    }

    public CharSequence ˋ() {
        return this.ˊ.getText();
    }

    public void setQuery(CharSequence charSequence, boolean z) {
        this.ˊ.setText(charSequence);
        if (charSequence != null) {
            this.ˊ.setSelection(this.ˊ.length());
            this.ˏˎ = charSequence;
        }
        if (z && !TextUtils.isEmpty(charSequence)) {
            ᐝ();
        }
    }

    public void setQueryHint(@Nullable CharSequence charSequence) {
        this.ˌ = charSequence;
        ʿ();
    }

    @Nullable
    public CharSequence ॱॱ() {
        if (this.ˌ != null) {
            return this.ˌ;
        }
        if (this.ॱॱ == null || this.ॱॱ.getHintId() == 0) {
            return this.ˊᐝ;
        }
        return getContext().getText(this.ॱॱ.getHintId());
    }

    public void setIconifiedByDefault(boolean z) {
        if (this.ˎˎ != z) {
            this.ˎˎ = z;
            ˎ(z);
            ʿ();
        }
    }

    public void setIconified(boolean z) {
        if (z) {
            ʻ();
        } else {
            ˊॱ();
        }
    }

    public boolean ʽ() {
        return this.ˍ;
    }

    public void setSubmitButtonEnabled(boolean z) {
        this.ˋˋ = z;
        ˎ(ʽ());
    }

    public void setQueryRefinementEnabled(boolean z) {
        this.ˋᐝ = z;
        if (this.ʽ instanceof SuggestionsAdapter) {
            ((SuggestionsAdapter) this.ʽ).setQueryRefinement(z ? 2 : 1);
        }
    }

    public void setSuggestionsAdapter(CursorAdapter cursorAdapter) {
        this.ʽ = cursorAdapter;
        this.ˊ.setAdapter(this.ʽ);
    }

    public void setMaxWidth(int i) {
        this.ˎˏ = i;
        requestLayout();
    }

    protected void onMeasure(int i, int i2) {
        if (ʽ()) {
            super.onMeasure(i, i2);
            return;
        }
        int mode = MeasureSpec.getMode(i);
        int size = MeasureSpec.getSize(i);
        switch (mode) {
            case Integer.MIN_VALUE:
                if (this.ˎˏ <= 0) {
                    size = Math.min(ॱˋ(), size);
                    break;
                } else {
                    size = Math.min(this.ˎˏ, size);
                    break;
                }
            case 0:
                if (this.ˎˏ <= 0) {
                    size = ॱˋ();
                    break;
                } else {
                    size = this.ˎˏ;
                    break;
                }
            case 1073741824:
                if (this.ˎˏ > 0) {
                    size = Math.min(this.ˎˏ, size);
                    break;
                }
                break;
        }
        int mode2 = MeasureSpec.getMode(i2);
        mode = MeasureSpec.getSize(i2);
        switch (mode2) {
            case Integer.MIN_VALUE:
                mode = Math.min(ʻॱ(), mode);
                break;
            case 0:
                mode = ʻॱ();
                break;
        }
        super.onMeasure(MeasureSpec.makeMeasureSpec(size, 1073741824), MeasureSpec.makeMeasureSpec(mode, 1073741824));
    }

    protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
        super.onLayout(z, i, i2, i3, i4);
        if (z) {
            ˏ(this.ˊ, this.ॱˋ);
            this.ʻॱ.set(this.ॱˋ.left, 0, this.ॱˋ.right, i4 - i2);
            if (this.ͺ == null) {
                this.ͺ = new a(this.ʻॱ, this.ॱˋ, this.ˊ);
                setTouchDelegate(this.ͺ);
                return;
            }
            this.ͺ.ॱ(this.ʻॱ, this.ॱˋ);
        }
    }

    private void ˏ(View view, Rect rect) {
        view.getLocationInWindow(this.ॱᐝ);
        getLocationInWindow(this.ॱˎ);
        int i = this.ॱᐝ[1] - this.ॱˎ[1];
        int i2 = this.ॱᐝ[0] - this.ॱˎ[0];
        rect.set(i2, i, view.getWidth() + i2, view.getHeight() + i);
    }

    private int ॱˋ() {
        return getContext().getResources().getDimensionPixelSize(o.ah.e.ʻ);
    }

    private int ʻॱ() {
        return getContext().getResources().getDimensionPixelSize(o.ah.e.ʽ);
    }

    private void ˎ(boolean z) {
        boolean z2;
        boolean z3 = true;
        int i = 8;
        this.ˍ = z;
        int i2 = z ? 0 : 8;
        if (TextUtils.isEmpty(this.ˊ.getText())) {
            z2 = false;
        } else {
            z2 = true;
        }
        this.ॱ.setVisibility(i2);
        ˊ(z2);
        View view = this.ˏॱ;
        if (z) {
            i2 = 8;
        } else {
            i2 = 0;
        }
        view.setVisibility(i2);
        if (!(this.ᐝॱ.getDrawable() == null || this.ˎˎ)) {
            i = 0;
        }
        this.ᐝॱ.setVisibility(i);
        ʾ();
        if (z2) {
            z3 = false;
        }
        ˋ(z3);
        ॱᐝ();
    }

    private boolean ᐝॱ() {
        if (this.ॱॱ == null || !this.ॱॱ.getVoiceSearchEnabled()) {
            return false;
        }
        Intent intent = null;
        if (this.ॱॱ.getVoiceSearchLaunchWebSearch()) {
            intent = this.ʿ;
        } else if (this.ॱॱ.getVoiceSearchLaunchRecognizer()) {
            intent = this.ʾ;
        }
        if (intent == null || getContext().getPackageManager().resolveActivity(intent, WXMediaMessage.THUMB_LENGTH_LIMIT) == null) {
            return false;
        }
        return true;
    }

    private boolean ॱˎ() {
        return (this.ˋˋ || this.ͺॱ) && !ʽ();
    }

    private void ˊ(boolean z) {
        int i = 8;
        if (this.ˋˋ && ॱˎ() && hasFocus() && (z || !this.ͺॱ)) {
            i = 0;
        }
        this.ˏ.setVisibility(i);
    }

    private void ॱᐝ() {
        int i = 8;
        if (ॱˎ() && (this.ˏ.getVisibility() == 0 || this.ˎ.getVisibility() == 0)) {
            i = 0;
        }
        this.ˊॱ.setVisibility(i);
    }

    private void ʾ() {
        int i = 1;
        int i2 = 0;
        int i3 = !TextUtils.isEmpty(this.ˊ.getText()) ? 1 : 0;
        if (i3 == 0 && (!this.ˎˎ || this.ॱͺ)) {
            i = 0;
        }
        ImageView imageView = this.ˋ;
        if (i == 0) {
            i2 = 8;
        }
        imageView.setVisibility(i2);
        Drawable drawable = this.ˋ.getDrawable();
        if (drawable != null) {
            drawable.setState(i3 != 0 ? ENABLED_STATE_SET : EMPTY_STATE_SET);
        }
    }

    private void ʼॱ() {
        post(this.ॱʼ);
    }

    void ʼ() {
        int[] iArr = this.ˊ.hasFocus() ? FOCUSED_STATE_SET : EMPTY_STATE_SET;
        Drawable background = this.ˋॱ.getBackground();
        if (background != null) {
            background.setState(iArr);
        }
        background = this.ˊॱ.getBackground();
        if (background != null) {
            background.setState(iArr);
        }
        invalidate();
    }

    protected void onDetachedFromWindow() {
        removeCallbacks(this.ॱʼ);
        post(this.ॱʻ);
        super.onDetachedFromWindow();
    }

    void ॱ(CharSequence charSequence) {
        ˎ(charSequence);
    }

    boolean ˏ(View view, int i, KeyEvent keyEvent) {
        if (this.ॱॱ == null || this.ʽ == null || keyEvent.getAction() != 0 || !keyEvent.hasNoModifiers()) {
            return false;
        }
        if (i == 66 || i == 84 || i == 61) {
            return ˋ(this.ˊ.getListSelection(), 0, null);
        }
        if (i != 21 && i != 22) {
            return (i == 19 && this.ˊ.getListSelection() == 0) ? false : false;
        } else {
            int i2;
            if (i == 21) {
                i2 = 0;
            } else {
                i2 = this.ˊ.length();
            }
            this.ˊ.setSelection(i2);
            this.ˊ.setListSelection(0);
            this.ˊ.clearListSelection();
            ʻ.ˊ(this.ˊ, true);
            return true;
        }
    }

    private CharSequence ˏ(CharSequence charSequence) {
        if (!this.ˎˎ || this.ʽॱ == null) {
            return charSequence;
        }
        int textSize = (int) (((double) this.ˊ.getTextSize()) * 1.25d);
        this.ʽॱ.setBounds(0, 0, textSize, textSize);
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("   ");
        spannableStringBuilder.setSpan(new ImageSpan(this.ʽॱ), 1, 2, 33);
        spannableStringBuilder.append(charSequence);
        return spannableStringBuilder;
    }

    private void ʿ() {
        CharSequence ॱॱ = ॱॱ();
        SearchAutoComplete searchAutoComplete = this.ˊ;
        if (ॱॱ == null) {
            ॱॱ = "";
        }
        searchAutoComplete.setHint(ˏ(ॱॱ));
    }

    private void ʽॱ() {
        int i = 1;
        this.ˊ.setThreshold(this.ॱॱ.getSuggestThreshold());
        this.ˊ.setImeOptions(this.ॱॱ.getImeOptions());
        int inputType = this.ॱॱ.getInputType();
        if ((inputType & 15) == 1) {
            inputType &= -65537;
            if (this.ॱॱ.getSuggestAuthority() != null) {
                inputType = (inputType | WXMediaMessage.THUMB_LENGTH_LIMIT) | 524288;
            }
        }
        this.ˊ.setInputType(inputType);
        if (this.ʽ != null) {
            this.ʽ.changeCursor(null);
        }
        if (this.ॱॱ.getSuggestAuthority() != null) {
            this.ʽ = new SuggestionsAdapter(getContext(), this, this.ॱॱ, this.ᐝᐝ);
            this.ˊ.setAdapter(this.ʽ);
            SuggestionsAdapter suggestionsAdapter = (SuggestionsAdapter) this.ʽ;
            if (this.ˋᐝ) {
                i = 2;
            }
            suggestionsAdapter.setQueryRefinement(i);
        }
    }

    private void ˋ(boolean z) {
        int i;
        if (this.ͺॱ && !ʽ() && z) {
            i = 0;
            this.ˏ.setVisibility(8);
        } else {
            i = 8;
        }
        this.ˎ.setVisibility(i);
    }

    void ˋ(CharSequence charSequence) {
        boolean z = true;
        CharSequence text = this.ˊ.getText();
        this.ˏˎ = text;
        boolean z2 = !TextUtils.isEmpty(text);
        ˊ(z2);
        if (z2) {
            z = false;
        }
        ˋ(z);
        ʾ();
        ॱᐝ();
        if (!(this.ˊˋ == null || TextUtils.equals(charSequence, this.ˑ))) {
            this.ˊˋ.ॱ(charSequence.toString());
        }
        this.ˑ = charSequence.toString();
    }

    void ᐝ() {
        CharSequence text = this.ˊ.getText();
        if (text != null && TextUtils.getTrimmedLength(text) > 0) {
            if (this.ˊˋ == null || !this.ˊˋ.ˋ(text.toString())) {
                if (this.ॱॱ != null) {
                    ॱ(0, null, text.toString());
                }
                this.ˊ.ˏ(false);
                ˈ();
            }
        }
    }

    private void ˈ() {
        this.ˊ.dismissDropDown();
    }

    void ʻ() {
        if (!TextUtils.isEmpty(this.ˊ.getText())) {
            this.ˊ.setText("");
            this.ˊ.requestFocus();
            this.ˊ.ˏ(true);
        } else if (!this.ˎˎ) {
        } else {
            if (this.ˋˊ == null || !this.ˋˊ.ˋ()) {
                clearFocus();
                ˎ(true);
            }
        }
    }

    void ˊॱ() {
        ˎ(false);
        this.ˊ.requestFocus();
        this.ˊ.ˏ(true);
        if (this.ˉ != null) {
            this.ˉ.onClick(this);
        }
    }

    void ॱˊ() {
        if (this.ॱॱ != null) {
            SearchableInfo searchableInfo = this.ॱॱ;
            try {
                if (searchableInfo.getVoiceSearchLaunchWebSearch()) {
                    getContext().startActivity(ˊ(this.ʿ, searchableInfo));
                } else if (searchableInfo.getVoiceSearchLaunchRecognizer()) {
                    getContext().startActivity(ˎ(this.ʾ, searchableInfo));
                }
            } catch (ActivityNotFoundException e) {
                Log.w("SearchView", "Could not find voice search activity");
            }
        }
    }

    void ˋॱ() {
        ˎ(ʽ());
        ʼॱ();
        if (this.ˊ.hasFocus()) {
            ˏॱ();
        }
    }

    public void onWindowFocusChanged(boolean z) {
        super.onWindowFocusChanged(z);
        ʼॱ();
    }

    public void ˎ() {
        setQuery("", false);
        clearFocus();
        ˎ(true);
        this.ˊ.setImeOptions(this.ॱʽ);
        this.ॱͺ = false;
    }

    public void ˊ() {
        if (!this.ॱͺ) {
            this.ॱͺ = true;
            this.ॱʽ = this.ˊ.getImeOptions();
            this.ˊ.setImeOptions(this.ॱʽ | 33554432);
            this.ˊ.setText("");
            setIconified(false);
        }
    }

    protected Parcelable onSaveInstanceState() {
        Parcelable savedState = new SavedState(super.onSaveInstanceState());
        savedState.ˎ = ʽ();
        return savedState;
    }

    protected void onRestoreInstanceState(Parcelable parcelable) {
        if (parcelable instanceof SavedState) {
            SavedState savedState = (SavedState) parcelable;
            super.onRestoreInstanceState(savedState.ˊ());
            ˎ(savedState.ˎ);
            requestLayout();
            return;
        }
        super.onRestoreInstanceState(parcelable);
    }

    void ͺ() {
        if (this.ॱˊ.getWidth() > 1) {
            int dimensionPixelSize;
            int i;
            Resources resources = getContext().getResources();
            int paddingLeft = this.ˋॱ.getPaddingLeft();
            Rect rect = new Rect();
            boolean ˎ = de.ˎ(this);
            if (this.ˎˎ) {
                dimensionPixelSize = resources.getDimensionPixelSize(o.ah.e.ᐝ) + resources.getDimensionPixelSize(o.ah.e.ˏ);
            } else {
                dimensionPixelSize = 0;
            }
            this.ˊ.getDropDownBackground().getPadding(rect);
            if (ˎ) {
                i = -rect.left;
            } else {
                i = paddingLeft - (rect.left + dimensionPixelSize);
            }
            this.ˊ.setDropDownHorizontalOffset(i);
            this.ˊ.setDropDownWidth((dimensionPixelSize + ((this.ॱˊ.getWidth() + rect.left) + rect.right)) - paddingLeft);
        }
    }

    boolean ˋ(int i, int i2, String str) {
        if (this.ˊˊ != null && this.ˊˊ.ॱ(i)) {
            return false;
        }
        ˊ(i, 0, null);
        this.ˊ.ˏ(false);
        ˈ();
        return true;
    }

    boolean ˋ(int i) {
        if (this.ˊˊ != null && this.ˊˊ.ˊ(i)) {
            return false;
        }
        ˏ(i);
        return true;
    }

    private void ˏ(int i) {
        CharSequence text = this.ˊ.getText();
        Cursor cursor = this.ʽ.getCursor();
        if (cursor != null) {
            if (cursor.moveToPosition(i)) {
                CharSequence convertToString = this.ʽ.convertToString(cursor);
                if (convertToString != null) {
                    ˎ(convertToString);
                    return;
                } else {
                    ˎ(text);
                    return;
                }
            }
            ˎ(text);
        }
    }

    private boolean ˊ(int i, int i2, String str) {
        Cursor cursor = this.ʽ.getCursor();
        if (cursor == null || !cursor.moveToPosition(i)) {
            return false;
        }
        ˋ(ˏ(cursor, i2, str));
        return true;
    }

    private void ˋ(Intent intent) {
        if (intent != null) {
            try {
                getContext().startActivity(intent);
            } catch (Throwable e) {
                Log.e("SearchView", "Failed launch activity: " + intent, e);
            }
        }
    }

    private void ˎ(CharSequence charSequence) {
        this.ˊ.setText(charSequence);
        this.ˊ.setSelection(TextUtils.isEmpty(charSequence) ? 0 : charSequence.length());
    }

    void ॱ(int i, String str, String str2) {
        getContext().startActivity(ˊ("android.intent.action.SEARCH", null, null, str2, i, str));
    }

    private Intent ˊ(String str, Uri uri, String str2, String str3, int i, String str4) {
        Intent intent = new Intent(str);
        intent.addFlags(268435456);
        if (uri != null) {
            intent.setData(uri);
        }
        intent.putExtra("user_query", this.ˏˎ);
        if (str3 != null) {
            intent.putExtra(SearchIntents.EXTRA_QUERY, str3);
        }
        if (str2 != null) {
            intent.putExtra("intent_extra_data_key", str2);
        }
        if (this.ـ != null) {
            intent.putExtra("app_data", this.ـ);
        }
        if (i != 0) {
            intent.putExtra("action_key", i);
            intent.putExtra("action_msg", str4);
        }
        intent.setComponent(this.ॱॱ.getSearchActivity());
        return intent;
    }

    private Intent ˊ(Intent intent, SearchableInfo searchableInfo) {
        String str;
        Intent intent2 = new Intent(intent);
        ComponentName searchActivity = searchableInfo.getSearchActivity();
        String str2 = "calling_package";
        if (searchActivity == null) {
            str = null;
        } else {
            str = searchActivity.flattenToShortString();
        }
        intent2.putExtra(str2, str);
        return intent2;
    }

    private Intent ˎ(Intent intent, SearchableInfo searchableInfo) {
        String string;
        String string2;
        String str = null;
        ComponentName searchActivity = searchableInfo.getSearchActivity();
        Intent intent2 = new Intent("android.intent.action.SEARCH");
        intent2.setComponent(searchActivity);
        Parcelable activity = PendingIntent.getActivity(getContext(), 0, intent2, 1073741824);
        Bundle bundle = new Bundle();
        if (this.ـ != null) {
            bundle.putParcelable("app_data", this.ـ);
        }
        Intent intent3 = new Intent(intent);
        String str2 = "free_form";
        int i = 1;
        Resources resources = getResources();
        if (searchableInfo.getVoiceLanguageModeId() != 0) {
            str2 = resources.getString(searchableInfo.getVoiceLanguageModeId());
        }
        if (searchableInfo.getVoicePromptTextId() != 0) {
            string = resources.getString(searchableInfo.getVoicePromptTextId());
        } else {
            string = null;
        }
        if (searchableInfo.getVoiceLanguageId() != 0) {
            string2 = resources.getString(searchableInfo.getVoiceLanguageId());
        } else {
            string2 = null;
        }
        if (searchableInfo.getVoiceMaxResults() != 0) {
            i = searchableInfo.getVoiceMaxResults();
        }
        intent3.putExtra("android.speech.extra.LANGUAGE_MODEL", str2);
        intent3.putExtra("android.speech.extra.PROMPT", string);
        intent3.putExtra("android.speech.extra.LANGUAGE", string2);
        intent3.putExtra("android.speech.extra.MAX_RESULTS", i);
        str2 = "calling_package";
        if (searchActivity != null) {
            str = searchActivity.flattenToShortString();
        }
        intent3.putExtra(str2, str);
        intent3.putExtra("android.speech.extra.RESULTS_PENDINGINTENT", activity);
        intent3.putExtra("android.speech.extra.RESULTS_PENDINGINTENT_BUNDLE", bundle);
        return intent3;
    }

    private Intent ˏ(Cursor cursor, int i, String str) {
        try {
            String columnString = SuggestionsAdapter.getColumnString(cursor, "suggest_intent_action");
            if (columnString == null) {
                columnString = this.ॱॱ.getSuggestIntentAction();
            }
            if (columnString == null) {
                columnString = "android.intent.action.SEARCH";
            }
            String columnString2 = SuggestionsAdapter.getColumnString(cursor, "suggest_intent_data");
            if (columnString2 == null) {
                columnString2 = this.ॱॱ.getSuggestIntentData();
            }
            if (columnString2 != null) {
                String columnString3 = SuggestionsAdapter.getColumnString(cursor, "suggest_intent_data_id");
                if (columnString3 != null) {
                    columnString2 = columnString2 + "/" + Uri.encode(columnString3);
                }
            }
            return ˊ(columnString, columnString2 == null ? null : Uri.parse(columnString2), SuggestionsAdapter.getColumnString(cursor, "suggest_intent_extra_data"), SuggestionsAdapter.getColumnString(cursor, "suggest_intent_query"), i, str);
        } catch (Throwable e) {
            int position;
            Throwable th = e;
            try {
                position = cursor.getPosition();
            } catch (RuntimeException e2) {
                position = -1;
            }
            Log.w("SearchView", "Search suggestions cursor at row " + position + " returned exception.", th);
            return null;
        }
    }

    void ˏॱ() {
        ʻ.ॱ(this.ˊ);
        ʻ.ˏ(this.ˊ);
    }

    static boolean ˎ(Context context) {
        return context.getResources().getConfiguration().orientation == 2;
    }
}
